﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kooboo.Commerce.Entities;

namespace Kooboo.Commerce.DataProvider
{
    public partial class Variation : Entity, IVariation
    {
   
        IBusinessType _BusinessType2;
        IBusinessType IVariation.BusinessType
        {
            get
            {
                if (this._BusinessType2 == null)
                {
                    this._BusinessType2 = this.DataContext.BusinessTypes
                        .Where(i => i.Id == this.BusinessTypeId)
                        .FirstOrDefault();
                }

                return this._BusinessType2;
            }
            set
            {
                this._BusinessType2 = value;
                this.BusinessTypeId = value.Id;
            }
        }

        IProductType _ProductType2;
        IProductType IVariation.ProductType
        {
            get
            {
                if (this._ProductType2 == null)
                {
                    this._ProductType2 = this.DataContext.ProductTypes
                        .Where(i => i.Id == this.ProductTypeId)
                        .FirstOrDefault();
                }

                return this._ProductType2;
            }
            set
            {
                this._ProductType2 = value;
                this.ProductTypeId = value.Id;
            }
        }



        #region IVariation Members


        public IQueryable<IProductVariation> ProductVariations
        {
            get {

                return this.DataContext.ProductVariationItems
                    .Where(i => i.VariationId == this.Id)
                    .Select(i => i.ProductVariation as IProductVariation);
            }
        }

        #endregion
    }
}
